
{%- liquid
  assign social_media_string = 'twitter,facebook,instagram,pinterest,snapchat,youtube,vimeo,tumblr,tiktok'
  assign social_media = social_media_string | split: ','
  assign show_media = false
  assign sameAs = ''
  assign sameAs_first = true
  for media in social_media
    assign social_link = media | append: '_link' | prepend: 'social_'
    if settings[social_link] != blank
      assign show_media = true
      assign social_json = settings[social_link] | json
      if sameAs_first
        assign sameAs = sameAs | append: social_json
        assign sameAs_first = false
      else
        assign sameAs = sameAs | append: ', ' | append: social_json
      endif
    endif
  endfor
-%}

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "Organization",
    "name": {{ shop.name | json }},
    "url": {{ request.origin | append: page.url | json }},
    {%- if settings.favicon %}
    "logo": "{{ settings.favicon | image_url: width: 32 | prepend: "https:" }}",
    {% endif -%}
    "address": {
      "@type": "PostalAddress",
      "addressLocality": "Hangzhou",
      "addressRegion": "Zhejiang",
      "streetAddress": "Dream Town, Yuhang District",
      "postalCode": "311100"
    },
    "contactPoint": [{
      "@type": "ContactPoint",
      "telephone": "(+1) 4323224776"
    }],
    {%- if show_media %}
    "sameAs": [{{ sameAs }}]{% endif -%}
  }
</script>

{%- if request.page_type == 'index' -%}
  {% assign potential_action_target = request.origin | append: routes.search_url | append: "?q={search_term_string}" %}
  <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "WebSite",
      "name": {{ shop.name | json }},
      "potentialAction": {
        "@type": "SearchAction",
        "target": {{ potential_action_target | json }},
        "query-input": "required name=search_term_string"
      },
      "url": {{ request.origin | append: page.url | json }}
    }
  </script>
{%- endif -%}

{%- assign position = 1 -%}
{%- assign breadcrumb_tags_item_name = current_tags | join: ' + ' -%}
{%- assign channelwill_current_tags_url_part = current_tags | join: '+' | downcase -%}

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "Website",
          "@id": "{{ shop.url }}",
          "name": "Home"
        }
      }
      {%- if article -%}
      {%- assign position = position | plus: 1 -%}
      ,{
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "Blog",
          "@id":  "{{ shop.url | append: blog.url }}",
          "name": "{{ blog.title | replace: '"', '&quot;' | escape_once }}"
        }
      }
      {%- assign position = position | plus: 1 -%}
      ,{
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "Article",
          "@id": "{{ shop.url | append: article.url }}",
          "name": "{{ article.title | replace: '"', '&quot;' | escape_once }}"
        }
      }
      {%- elsif blog and article == nil -%}
      {%- assign position = position | plus: 1 -%}
      ,{
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "Blog",
          "@id":  "{{ shop.url | append: blog.url }}",
          "name": "{{ blog.title | replace: '"', '&quot;' | escape_once }}"
        }
      }
      {%- if current_tags -%}
        {%- assign position = position | plus: 1 -%}
        ,{
          "@type": "ListItem",
          "position": {{ position }},
          "item": {
            "@type": "Blog",
            "@id":  "{{ shop.url | append: blog.url | append: '/' | append: channelwill_current_tags_url_part }}",
            "name": "{{ breadcrumb_tags_item_name }}"
          }
        }
      {%- endif -%}
      {%- elsif product -%}
      {%- assign product_breadcrumb_url = shop.url | append: '/products/' | append: product.handle -%}
      {%- if collection and collection.url != blank -%}
      {%- assign position = position | plus: 1 -%}
      {%- assign product_breadcrumb_url = shop.url | append: collection.url | append: '/products/' | append: product.handle -%}
      ,{
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "CollectionPage",
          "@id":  "{{ shop.url | append: collection.url }}",
          "name": "{{ collection.title | replace: '"', '&quot;' | escape_once }}"
        }
      }
      {%- endif -%}
      {%- assign position = position | plus: 1 -%}
      ,{
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "WebPage",
          "@id": "{{ product_breadcrumb_url }}",
          "name": "{{ product.title | replace: '"', '&quot;' | escape_once }}"
        }
      }
      {%- elsif collection and product == nil -%}
      {%- assign position = position | plus: 1 -%}
      ,{
        "@type": "ListItem",
        "position": {{ position }},
        "item": {
          "@type": "CollectionPage",
          "@id":  "{{ shop.url | append: collection.url }}",
          "name": "{{ collection.title | replace: '"', '&quot;' | escape_once }}"
        }
      }
      {%- if current_tags -%}
        {%- assign position = position | plus: 1 -%}
        ,{
          "@type": "ListItem",
          "position": {{ position }},
          "item": {
            "@type": "CollectionPage",
            "@id":  "{{ shop.url | append: collection.url | append: '/' | append: channelwill_current_tags_url_part }}",
            "name": "{{ breadcrumb_tags_item_name }}"
          }
        }
      {%- endif -%}
    {%- endif -%}
    ]
  }
</script>
